package com.wxx.vo;

import lombok.Data;

import java.io.Serializable;

/**
 * 后端统一返回结果
 */
@Data
public class Result<T> implements Serializable {

    private Integer code;

    private String message;

    private T data;

    public static <T> Result<T> success(T obj){
        Result<T> result = new Result<>();
        result.data = obj;
        result.code = 200;
        result.message = "success";
        return result;
    }

    public static <T> Result<T> fail(String message){
        Result<T> result = new Result<>();
        result.code = 500;
        result.message = message;
        return result;
    }

    @Override
    public String toString() {
        return "Result{" +
                "code=" + code +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
